package com.modai.controller;

import com.modai.dto.CommonResponse;
import com.modai.dto.UserJwt;
import lombok.SneakyThrows;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

import static com.modai.dto.CommonResponse.STATUS.*;

/**
 * @author ：modai
 * @date ：Created in 2021-6-6 11:48
 * @description：登录
 */
@RequestMapping(value = "/login")
@RestController
public class LoginController {
    @SneakyThrows
    @PostMapping
    public CommonResponse<UserJwt> login(
            @RequestParam("username") String username,
            @RequestParam("password") String password
    ){
        if (Objects.equals(username, "admin") && Objects.equals(password, "123")){
            return new CommonResponse<>(
                    SUCCESS,
                    UserJwt.builder()
                            .username("admin")
                            .accessToken("asdfasdfasfqwfw234")
                            .refreshToken("1de323r2")
                            .build());
        }
        throw new NoSuchFieldException(username+": user login faild");
    }
}
